package com.xbongbong.saas.domain.dao;

import com.xbongbong.saas.domain.entity.PurchaseUserEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/2/21 15:16
 * @since v1.0
 */
@Repository
@Mapper
public interface PurchaseUserDao {
    /**
     * 插入数据
     *
     * @param purchaseUser 采购合同负责人实体数据
     * @return 是否成功
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     **/
    Integer insert(PurchaseUserEntity purchaseUser);
    /**
     * 更新数据
     *
     * @param purchaseUser 采购合同产品实体数据
     * @return 是否成功
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     **/
    Integer update(PurchaseUserEntity purchaseUser);

    void insertBatch(List<PurchaseUserEntity> purchaseUserList);
    /**
     * 根据主键删除记录
     *
     * @param key    主键
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 获取一条采购合同产品数据
     *
     * @param key 采购合同产品ID
     * @param corpid 公司id
     * @return PurchaseProductEntity 一条数据实体
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    PurchaseUserEntity getByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 多参数查询多条数据
     *
     * @param param 参数集合
     * @return List<PurchaseProductEntity> 数据集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<PurchaseUserEntity> findEntitys(@Param("param") Map<String, Object> param);

    Integer getEntitysCount(@Param("param") Map<String, Object> param);

    Integer deleteByPurchaseId(@Param("purchaseId") Long purchaseId, @Param("corpid") String corpid);

    Integer deleteByUserIdAndPurchaseId(@Param("userId") String userId, @Param("purchaseId") Long purchaseId, @Param("corpid") String corpid);

    Integer deleteByUserIdAndPurchaseIdIn(@Param("userId") String userId, @Param("purchaseIdIn") List<Long> purchaseIdIn,
                                          @Param("corpid") String corpid, @Param("isMain") Integer isMain);

    List<UserTeamEntity> findBaseEntitys(@Param("param") Map<String,Object> map);

    List<Long> getDataIdList(@Param("corpid") String corpid, @Param("isMain") Integer isMain, @Param("userIdIn") List<String> userId);

    /**
     * 批量修改
     *
     * @param corpid
     * @param dataIdIn
     * @param isMain
     * @param del
     */
    void batchUpdateByIdIn(@Param("corpid")String corpid, @Param("idIn")List<Long> dataIdIn, @Param("isMain")Integer isMain, @Param("del")Integer del);

    /**
     * 获取团队
     *
     * @param corpid 公司id
     * @param purchaseId 合同id
     * @param isMain 是否主负责人
     * @author chenshan
     * @return java.util.List<java.lang.String>
     * @date 2020/3/6 20:34
     */
    List<String> getPurchaseUserIdList(@Param("corpid") String corpid, @Param("purchaseId") Long purchaseId, @Param("isMain") Integer isMain);

    /**
     * 获取采购合同团队userIdList集合
     *
     * @param corpid 公司id
     * @param purchaseIds 采购合同id集合
     * @param isMain 是否主负责人
     * @return java.util.List<java.lang.String>
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    List<String> getPurchaseUserIdListByIn(@Param("corpid") String corpid, @Param("purchaseIds") List<String> purchaseIds, @Param("isMain") Integer isMain);

    void batchDeleteById(@Param("corpid") String corpid, @Param("idIn") List<Long> removeIdList);

    Integer deleteBatch(@Param("list") List<Long> list, @Param("corpid") String corpid,@Param("del") Integer del);

    Integer updateBatch(@Param("list") List<PurchaseUserEntity> list, @Param("corpid")  String corpid);

    void deleteByDataIds(@Param("dataIdIn") List<Long> dataIds, @Param("corpid") String corpid);

    /**
     * 批量修改团队里面成员为协同人以及协同人可编辑权限
     *
     * @param corpid
     * @param idIn
     * @param isMain
     * @param formPermission
     */
    void batchUpdateCoAndPerByUserIdIn(@Param("corpid")String corpid, @Param("idIn")List<Long> idIn, @Param("isMain")Integer isMain, @Param("formPermission")Integer formPermission);

}
